package top.jiangqiang.qyblog.common.base.query;

import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;

/**
 * @author jiangqiang
 * @date 2022-12-03
 */
@NoArgsConstructor
@Schema(name = "分页查询")
@JsonIgnoreProperties({"optimizeCountSql", "orders", "searchCount", "optimizeJoinOfCountSql", "maxLimit", "countId"})
public class PageResult<T> extends PageDTO<T> implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    @JsonProperty(value = "totalPages", index = 1)
    @Schema(description = "总共多少页")
    @Override
    public long getPages() {
        return super.getPages();
    }

    @JsonProperty(value = "totalCount", index = 2)
    @Schema(description = "总共多少条数据")
    @Override
    public long getTotal() {
        return super.getTotal();
    }

    @JsonProperty(value = "currentPage", index = 3)
    @Schema(description = "当前页数，从1开始")
    @Override
    public long getCurrent() {
        return super.getCurrent();
    }

    @JsonProperty(value = "pageSize", index = 4)
    @Schema(description = "每一页数量")
    @Override
    public long getSize() {
        return super.getSize();
    }

    @JsonProperty(value = "records", index = 5)
    @Schema(description = "分页的数据列表")
    @Override
    public List<T> getRecords() {
        return super.getRecords();
    }

    /**
     * @param currentPage 当前查询的是第几页
     * @param pageSize    每一页的数量
     */
    public PageResult(long currentPage, long pageSize) {
        this.current = currentPage;
        this.size = pageSize;
    }

}
